<?php
namespace AuctionCore\FoursStore;
/**
 * 用户登录管理
 */
use AuctionCore\Account\Back\Employee;

/**
 * 车源列表
 * @author       Eric Lee
 */
class IndexShow  {

    /**
     * 查询数量
     * @return [type] [description]
     */
    public function counts($map){
        $map1['suggest_max_price'] = array('gt',0);
        $map1['suggest_min_price'] = array('gt',0);
        $map = array_merge($map,$map1);
              $buildSql =  M('cars')->alias('c')
                ->field('c.car_id')
                ->join( "LEFT JOIN ".C('DB_PREFIX') . "order o ON c.car_id=o.car_id")
                ->join(C('DB_PREFIX')."car_owner as co ON co.owner_id=c.owner_id")
                ->where($map)->order('order_id desc')
                ->buildSql();
      $buildSql1 = M()->table($buildSql.' a')->group('car_id')->buildSql();
      $total = M()->table($buildSql1.' b')->count();
        return $total;
    }
    /**
     * 获取参拍的数量
     * @return [type] [description]
     */
    public function carStat($m){
        if ($m['co.comefrom'][1]) {
            if(is_array($m['co.comefrom'][1])){
                $four_id = implode(',', $m['co.comefrom'][1]);
            }else{
                $four_id = $m['co.comefrom'][1];
            }
            $cond = " AND posttime>='".date('Y-m-01 00:00:00',time())."' AND posttime<='".date('Y-m-t 23:59:59',time())."'";
            $subSql = "select count(*) t from au_cars where owner_id in (select owner_id from au_car_owner co inner join au_come_from cf on co.comefrom=cf.from_id where co.comefrom in(".$four_id.")) $cond";
            $result = M()->query($subSql);
        // echo M()->getLastSql();
        // dump($result,true,null,false);
            return $result[0]['t'];
        }
        else{
            return 0 ;
        }
        
    }

    public function getInfo($m){        
        //待上拍
        $map1['c.car_status'] = array('in',array(4,7));
        $map1['o.status'] = array('in',array(1,2));
        $map1['_logic'] = 'OR';
        $map11['_complex'] = $map1;
        $mapNew1 = array_merge($map11,$m);
        $info1 = $this->counts($mapNew1);
        //拍卖中
        $map2['o.status'] = array('in', array('3','301','4'));
        $mapNew2 = array_merge($map2,$m);
        $info2 = $this->counts($mapNew2);
        // 待确认
        $map3['o.status'] = array('eq',5);
        $mapNew3 = array_merge($map3,$m);
        $info3 = $this->counts($mapNew3);
        // 交易中
        $map4['o.status'] = array('in', array(7,8,9,10,11));
        $mapNew4 = array_merge($map4,$m);
        $info4 = $this->counts($mapNew4);
        // 参拍量
        $map5['c.posttime'] = array(array('egt',date('Y-m-01 00:00:00',time())), array('elt',date('Y-m-t 23:59:59',time())));
        // $map5['co.business_status'] = array('notin', array(1,2,3,4,6));
        
        $mapNew5 = array_merge($map5,$m);
        $info5 = $this->counts($mapNew5);
        $info5 = $this->carStat($m);
        // 交易成功
        $map6['co.check_date'] = array(array('egt',date('Y-m-01 00:00:00',time())), array('elt',date('Y-m-t 23:59:59',time())));
        $map6['c.car_status'] = array('eq', 9);
        $mapNew6 = array_merge($map6,$m);
        $info6 = $this->counts($mapNew6);
        // 交易失败
        $map7['co.check_date'] = array(array('egt',date('Y-m-01 00:00:00',time())), array('elt',date('Y-m-t 23:59:59',time())));
        $map7['c.car_status'] = array('eq', 8);
        $mapNew7 = array_merge($map7,$m);
        $info7 = $this->counts($mapNew7);
        $info = array(
                'info1' => $info1,
                'info2' => $info2,
                'info3' => $info3,
                'info4' => $info4,
                'info5' => $info5,
                'info6' => $info6,
                'info7' => $info7
            );
        // echo M()->getLastSql();
        return $info;
    }

}